//
//  CYHeaderFooterView.m
//  CaiYun
//
//  Created by 今日信息科技 on 2017/6/20.
//  Copyright © 2017年 今日信息科技. All rights reserved.
//

#import "CYHeaderFooterView.h"
#import "CYTrendSource.h"
#import "CYCycleScroll.h"
#define GAP AL(10)
@implementation CYHeaderFooterView
/*初始化cell的头视图和尾视图*/
+ (UIView *)getHeaderOrFooterForTableiView:(NSString *)lotteryName{
    TrendType type = [CYTrendSource getType:lotteryName];
    
    UIView *view =  [[UIView alloc]initWithFrame:CGRectMake(0.0, 0.0, SCREEN_WIDTH, AL(33))];
    view.backgroundColor = LINE_COLOR;

    CYLabel *dateLBL = [[CYLabel alloc]initWithText:@"期号" size:16 textcolor:TEXT_GRAY_COLOR];
    [view addSubview:dateLBL];
    
    [dateLBL mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(view).with.offset(2 * GAP);
        make.centerY.equalTo(view);
        make.size.mas_equalTo(dateLBL.bounds.size);
    }];
    
    CYLabel *winLBL = [[CYLabel alloc]initWithText:[self getWinNumLBLText:type] size:16 textcolor:TEXT_GRAY_COLOR];
    [view addSubview:winLBL];
    
    [winLBL mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(view).with.offset([CYTrendSource getWinNumLBLCenterX:type]);
        make.centerY.equalTo(view);
        make.size.mas_equalTo(winLBL.bounds.size);
    }];
    
    
    CYLabel *rightLBL = [[CYLabel alloc]initWithText:[self getRightLBLText:type] size:16 textcolor:TEXT_GRAY_COLOR];
    [view addSubview:rightLBL];
    
    [rightLBL mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(view).with.offset([CYTrendSource getRightLBLCenterX:type]);
        make.centerY.equalTo(view);
        make.size.mas_equalTo(rightLBL.bounds.size);
    }];
    
    CYLabel *rightSecLBL = [[CYLabel alloc]initWithText:[self getRightSecLBLText:type] size:16 textcolor:TEXT_GRAY_COLOR];
    [view addSubview:rightSecLBL];
    
    [rightSecLBL mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(view).with.offset([CYTrendSource getRightSecLBLCenterX:type]);
        make.centerY.equalTo(view);
        make.size.mas_equalTo(rightSecLBL.bounds.size);
    }];
    
    CYLabel *midLBL = [[CYLabel alloc]initWithText:[self getMidLBLText:type] size:16 textcolor:TEXT_GRAY_COLOR];
    [view addSubview:midLBL];
    
    [midLBL mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(view).with.offset([CYTrendSource getMidLBLCenterX:type]);
        make.centerY.equalTo(view);
        make.size.mas_equalTo(midLBL.bounds.size);
    }];
    
    /*子控件是否隐藏*/
    rightLBL.hidden = (type != PKShiType)?NO:YES;
    rightSecLBL.hidden = (type != PKShiType)?NO:YES;
    midLBL.hidden = (type == KuaiSanType || type == ShiShiCaiType)?NO:YES;
    /*end*/
    UIView *top_line = [[UIView alloc]initWithFrame:CGRectMake(0.0, 0.0, SCREEN_WIDTH, 0.5)];
    top_line.backgroundColor = LINE_COLOR;
    [view addSubview:top_line];
    
    UIView *bottom_line = [[UIView alloc]initWithFrame:CGRectMake(0.0, AL(32.5), SCREEN_WIDTH, 0.5)];
    bottom_line.backgroundColor = LINE_COLOR;
    [view addSubview:bottom_line];
    return view;
}

+ (NSString *)getWinNumLBLText:(TrendType)type{
    if (type == PKShiType) return @"开奖号码";
    else return @"开奖号";
}

+ (NSString *)getRightLBLText:(TrendType)type{
    if (type == KuaiSanType) return @"单双";
    else if (type == ShiShiCaiType) return @"后三";
    else if (type == DiPinCaiType || type == ShiYiXuanWuType) return @"跨度";
    else if (type == ShiShiLeType) return @"形态";
    else return nil;
}

+ (NSString *)getRightSecLBLText:(TrendType)type{
    if (type == KuaiSanType) return @"大小";
    else if (type == ShiShiCaiType) return @"个位";
    else if (type == DiPinCaiType || type == ShiYiXuanWuType || type == ShiShiLeType) return @"和值";
    else return nil;
}

+ (NSString *)getMidLBLText:(TrendType)type{
    if (type == KuaiSanType) return @"和值";
    else if (type == ShiShiCaiType) return @"十位";
    else return nil;
}


+ (UIView *)getHeaderForCollectionView{
    UIView *view = [[UIView alloc]init];
    view.backgroundColor = [UIColor whiteColor];
    NSString *imageStr = ([CYUser shareUser].token)?@"kefu":@"sw";
    NSString *titleStr = ([CYUser shareUser].token)?@"在线客服":@"免费试玩";
    NSArray *array = @[@{@"title":@"存/取款",@"img":@"cunkuan"},@{@"title":@"优惠活动",@"img":@"youhui"},@{@"title":@"走势图表",@"img":@"zoushi"},@{@"title":titleStr,@"img":imageStr}];
    /*创建scroll滚动轮播图*/
    CYCycleScroll *cycleScroll  = [[CYCycleScroll alloc]initWithFrame:CGRectMake(0.0, 0.0, SCREEN_WIDTH, AL(PT(378 / 750.0 * SCREEN_WIDTH * 2)))];
    
    NSArray *lunboArr = [CYCache getCache:@"Lottery.plist"][@"lunbo"];
    NSMutableArray *newArr = [NSMutableArray array];
    for (NSDictionary *dict in lunboArr) {
        if (IS_PHONE && [dict[@"type"] intValue] == 2) //手机终端
            [newArr addObject:dict[@"address"]];
        else if (!IS_PHONE && [dict[@"type"] intValue] == 3)//平板终端
            [newArr addObject:dict[@"address"]];
    }
    cycleScroll.imageNames = newArr;//从本地获取轮播图地址
    [view addSubview:cycleScroll];
    
    
    [cycleScroll mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(view);
        make.top.equalTo(view).with.offset(0);
        make.size.mas_equalTo(CGSizeMake(SCREEN_WIDTH, AL(PT(378 / 750.0 * SCREEN_WIDTH * 2))));
    }];
    
    /*灰色背景条*/
    CYView *grayLine = [[CYView alloc]initWithColor:LINE_COLOR];
    [view addSubview:grayLine];
    
    [grayLine mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(view);
        make.top.equalTo(cycleScroll.mas_bottom).with.offset(0);
        make.size.mas_equalTo(CGSizeMake(SCREEN_WIDTH, AL(PT(10))));
    }];
    
    /*创建section==0 四个按钮 和 提示高频彩*/
    for (int i = 0; i < 4; i ++) {
        
        CYButton *button = [[CYButton alloc]init];
        [button addTarget:nil action:@selector(abcd:) forControlEvents:UIControlEventTouchUpInside];
        button.tag = 200 + i;
        [view addSubview:button];
        
        [button mas_updateConstraints:^(MASConstraintMaker *make) {
            make.edges.mas_offset(UIEdgeInsetsMake(AL(PT(378 / 750.0 * SCREEN_WIDTH * 2 + 10)), SCREEN_WIDTH / 4.0 * i, AL(PT(40)), SCREEN_WIDTH / 4.0 * (3 - i)));
        }];
        
        __weak __typeof (CYButton *)weakbutton = button;
        
        /*按钮图片*/
        CYImageView *img = [[CYImageView alloc]initWithImage:[UIImage imageNamed:array[i][@"img"]]];
        [button addSubview:img];
        
        [img mas_updateConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(weakbutton).with.offset(AL(PT(26)));
            make.centerX.equalTo(weakbutton);
            make.size.mas_equalTo(CGSizeMake(AL(PT(50)), AL(PT(50))));
        }];
        
        /*按钮文字*/
        CYLabel *title = [[CYLabel alloc] initWithText:array[i][@"title"] size:13 textcolor:[UIColor grayColor]];
        [button addSubview:title];
        
        [title mas_updateConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(img.mas_bottom).with.offset(AL(PT(20)));
            make.centerX.equalTo(button);
            make.size.mas_equalTo(title.bounds.size);
        }];
    }
    UIView *bottom = [self getFooterForCollectionView:0];
    [view addSubview:bottom];
    
    [bottom mas_updateConstraints:^(MASConstraintMaker *make) {
        make.edges.mas_offset(UIEdgeInsetsMake(AL(PT(150 + 378 / 750.0 * SCREEN_WIDTH * 2  +10)), 0, 0, 0));
    }];
    
    return view;
}


+ (UIView *)getFooterForCollectionView:(NSUInteger)section{
    //0代表低频彩   1  代表高频彩
    /*高频彩背景灰条*/
    CYView *bottomView = [[CYView alloc]initWithColor:LINE_COLOR];
    
    /*右边划线*/
    CYView *leftLine = [[CYView alloc]initWithColor:RGBA(250, 93, 33, 1) line:LineLeft lineColor:LINE_COLOR];
    [bottomView addSubview:leftLine];
    
    [leftLine mas_updateConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(bottomView).with.offset(AL(PT(24)));
        make.centerY.equalTo(bottomView);
        make.size.mas_equalTo(CGSizeMake(AL(2), AL(PT(30))));
    }];
    
    /*高频彩*/
    NSString *title = (section == 0)?@"高频彩":@"低频彩";
    CYLabel *titleLBL = [[CYLabel alloc]initWithText:title size:13 textcolor:nil];
    [bottomView addSubview:titleLBL];
    
    [titleLBL mas_updateConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(bottomView).with.offset(AL(PT(24 + 12) + 2));
        make.centerY.equalTo(bottomView);
        make.size.mas_equalTo(titleLBL.bounds.size);
    }];
    
    /*提示*/
    NSString *tips = (section == 0)?@"10分钟开奖 简单易用":@"以小搏大 彩渲人生";
    CYLabel *tipsLBL = [[CYLabel alloc]initWithText:tips size:11 textcolor:TEXT_GRAY_COLOR];
    [bottomView addSubview:tipsLBL];
    
    [tipsLBL mas_updateConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(titleLBL.mas_right).with.offset(AL(PT(30)));
        make.centerY.equalTo(bottomView);
        make.size.mas_equalTo(tipsLBL.bounds.size);
    }];
    
    return (UIView *)bottomView;
}
@end
